<template>
    <div class="flyDuck-app-home">
        <el-container>
            <el-header class="flyDuck-app-home-header">

                <div class="title">flyduck平台</div>
                <el-dropdown class="userInfo" @command="commandHandler">
                      <span class="el-dropdown-link">
                        {{user.nickName}}<i><img :src="user.avatar"></i>
                      </span>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="userCenter">个人中心</el-dropdown-item>
                        <el-dropdown-item command="setting">设置</el-dropdown-item>
                        <el-dropdown-item command="logout">注销登录</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </el-header>
            <el-container class="flyDuck-app-home-container">
                <el-aside width="200px">
                    <el-menu router unique-opened>
                        <el-submenu :index="index+''" v-for="(item,index) in routes" :key="index" v-if="!item.hidden">
                            <template slot="title">
                                <i :class="item.icon" style="color: #1accff;margin-right: 5px"></i>
                                <span>{{item.name}}</span>
                            </template>
                            <el-menu-item :index="children.path" v-for="(children,indexj) in item.children">
                                <template slot="title">
                                    <i :class="children.icon" style="color: #1accff;margin-right: 5px"></i>
                                    <span>{{children.name}}</span>
                                </template>

                            </el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main class="flyDuck-app-home-main">
                    <el-breadcrumb separator-class="el-icon-arrow-right" v-if="this.$router.currentRoute.path!='/home'">
                        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                        <el-breadcrumb-item>{{this.$router.currentRoute.name}}</el-breadcrumb-item>
                    </el-breadcrumb>
                    <div class="flyDuck-app-home-main-welcome" v-if="this.$router.currentRoute.path=='/home'">
                        欢迎来到flyduck平台
                    </div>
                    <router-view/>
                </el-main>
            </el-container>
        </el-container>
    </div>
</template>
<script>
    import {logout} from "@/api/login";

    export default {
        name: "Home",
        computed:{
            routes(){
                return this.$store.state.routes;
            }
        },
        data() {
            return {
                user: JSON.parse(window.sessionStorage.getItem('loginInfo')).userInfo,
            };
        },
        methods: {
            commandHandler(command){
                if(command =='logout'){
                    // 注销登录
                    logout();
                    //清空用户信息
                    window.sessionStorage.removeItem('token');
                    window.sessionStorage.removeItem('loginInfo');
                    // 清空菜单
                    this.$store.commit('initRoutes',[]);
                    //跳转登录
                    this.$router.replace('/')
                }
                if(command == 'userCenter'){
                    this.$router.push('/userCenter')
                }
            }
        },
    }
</script>
<style>
    .flyDuck-app-home-header{
        background: #409eff;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 15px;
        box-sizing: border-box;
    }
    .flyDuck-app-home-header.title{
        font-size: 30px;
        font-family: 华文楷体;
        color: white;
    }
    .flyDuck-app-home-header.userInfo{
        cursor: pointer;
    }
    .el-dropdown-link img{
        width: 48px;
        height: 48px;
        border-radius: 24px;
        margin-left: 8px;
    }
    .flyDuck-app-home-main-welcome{
        text-align: center;
        font-size: 30px;
        font-family: 华文楷体;
        color: #209eff;
        padding-top: 50px;
    }
</style>

